<?php

define('INTERFACE_CODE', md5('free_youtube_download_20120504'));
define('DATA_SAVE_PATH','/var/www/website/cms.wondershare.com/httpdocs/image2/free_youtube_download/');

//note 接口合法性验证
if( $_GET['code'] != INTERFACE_CODE ) exit('error code!');


function gather(){
	createFolder( DATA_SAVE_PATH );
	
	$str = "";
	foreach( $_POST as $v ){
		$str .= $v."\t";
	}
	$str .= "\n";
	
	writeFile( DATA_SAVE_PATH.'free_youtube_download_data.txt', $str );
}




/**
 * 将数据写入文件
 * @param string $file 要写入的文件
 * @param string $data 要写入文件的数据
 * @param string $type 写入文件类型
 * @return boolean
 * */
function writeFile($file, $data, $type='a') {
	$fp = @fopen($file, $type);
	flock($fp, LOCK_EX);
	fwrite($fp, $data);
	flock($fp, LOCK_UN);
	fclose($fp);
	return true;
}

/**
 * 创建多级目录
 * @param string $dir 要创建的文件夹路径
 * @param string $mask 文件夹权限
 * @return boolean
 * */
function createFolder($dir, $mask=0777){
	if (!file_exists($dir)){
		createFolder(dirname($dir));
		umask(0);
		mkdir($dir, $mask);
	}
	return true;
}


$m = $_GET['m'];
$m();